package com.sinba.common.news.action;

import com.opensymphony.xwork2.ActionSupport;

import com.sinba.common.dto.PageDTO;
import com.sinba.common.news.dto.TopicDTO;
import com.sinba.common.news.service.ITopicService;

import org.springframework.beans.factory.annotation.Autowired;

@SuppressWarnings( "serial" )
public class TopicAction
    extends ActionSupport
{
    @Autowired
    private ITopicService topicService;
    private PageDTO pageDTO;
    private TopicDTO topicDTO = new TopicDTO(  );
    private Long[] ids;
    private String sord;
    private String sidx;
    private int page = 1;
    private int rows = 10;

    public PageDTO getPageDTO(  )
    {
        return pageDTO;
    }

    public void setPageDTO( PageDTO pageDTO )
    {
        this.pageDTO = pageDTO;
    }

    public TopicDTO getTopicDTO(  )
    {
        return topicDTO;
    }

    public void setTopicDTO( TopicDTO topicDTO )
    {
        this.topicDTO = topicDTO;
    }

    public Long[] getIds(  )
    {
        return ids;
    }

    public void setIds( Long[] ids )
    {
        this.ids = ids;
    }

    public String getSord(  )
    {
        return sord;
    }

    public void setSord( String sord )
    {
        this.sord = sord;
    }

    public String getSidx(  )
    {
        return sidx;
    }

    public void setSidx( String sidx )
    {
        this.sidx = sidx;
    }

    public int getPage(  )
    {
        return page;
    }

    public void setPage( int page )
    {
        this.page = page;
    }

    public int getRows(  )
    {
        return rows;
    }

    public void setRows( int rows )
    {
        this.rows = rows;
    }

    public String findTopicPager(  )
    {
        int start = ( page - 1 ) * rows;
        topicDTO.setStart( start );
        topicDTO.setLimit( rows );
        pageDTO = topicService.findTopicPager( topicDTO, sord, sidx );

        if ( pageDTO != null )
        {
            pageDTO.setPage( page );
            pageDTO.setRows( rows );
        }

        return SUCCESS;
    }

    public String saveTopic(  )
    {
        topicService.saveTopic( topicDTO );

        return SUCCESS;
    }

    public String editTopic(  )
    {
        topicService.editTopic( topicDTO );

        return SUCCESS;
    }

    public String deleteTopic(  )
    {
        topicService.deleteTopic( ids );

        return SUCCESS;
    }

    public String findTopicInfo(  )
    {
        topicDTO = topicService.findTopicInfo( topicDTO.getTopicId(  ) );

        return "topicDTO";
    }
}
